import 'dart:async';

import 'package:flutter_app/config/urlServer.dart';
import 'package:dio/dio.dart';



class HttpServe{
  Map<String,dynamic> options = {};
  Dio dio;
  static HttpServe _instance;
  HttpServe._internal() {
    dio = Dio(BaseOptions(
        connectTimeout:5000,
        receiveTimeout:3000,
        baseUrl:UrlServe.BASE_URL
    ));
  }
  static HttpServe _getInstance() {
    if (_instance == null) {
      _instance = new HttpServe._internal();
    }
    return _instance;
  }
  factory HttpServe(){
    return HttpServe._getInstance();
  }
  Future get(url,[data])async{
    var response = await dio.get(url,queryParameters:data);
    return response;
  }
 Future post(url,[data]) async{
    var response = await dio.post(url,data: data);
    return response;
  }
  Future downFile(url,name) async{
    var response = await dio.download(url, name);
    return response;
  }

  Future uploadFile(url,formData,[onSendProgress]) async{
    var response = await dio.post(url, data:formData,onSendProgress:onSendProgress);
    return response;
  }
}